insert overwrite table jms_dm.dm_cusc_tyd_taking_customer_summary_dt partition (dt)
select proxy_area_code                                            --代理区code
     , proxy_area_name                                            --代理区名称
     , pick_network_code                                          --取件网点code
     , pick_network_name                                          --取件网点名称
     , customer_code                                              --客户编号code
     , customer_name                                              --客户编号名称
     , order_source_code                                          --订单来源code
     , order_source_name                                          --订单来源名称
     , sum(if(order_status_code <> '104', 1, 0)) as waybill_total --订单票数
     , sum(if(order_status_code = '103', 1, 0))  as taking_num    --已揽收票数
     , date_time
     , fran_code
     , fran_name
     , date_time                                 as dt
from jms_dm.dm_cusc_tyd_taking_waybill_detail_dt
where dt >= date_add('{{ execution_date | cst_ds }}', -6)
  and dt <= '{{ execution_date | cst_ds }}'
group by proxy_area_code
       , proxy_area_name
       , pick_network_code
       , pick_network_name
       , customer_code
       , customer_name
       , order_source_code
       , order_source_name
       , date_time
       , fran_code
       , fran_name
    distribute by dt
;